
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>消息驱动Rabbitmq · tgor note</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="tgor">
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-chapter-fold/chapter-fold.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-splitter/splitter.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-tbfed-pagefooter/footer.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-page-toc-button/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search-pro/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-back-to-top-button/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-code/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="../category/数据库.html" />
    
    
    <link rel="prev" href="../Java-其他库/分布式系统及CAP原理.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    Me
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../category/微服务.html">
            
                <a href="../category/微服务.html">
            
                    
                    微服务
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="../Java-Spring/Feign.html">
            
                <a href="../Java-Spring/Feign.html">
            
                    
                    HTTP客户端Feign
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="../Java-其他库/限流.html">
            
                <a href="../Java-其他库/限流.html">
            
                    
                    限流
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3" data-path="../运维/Nginx限流.html">
            
                <a href="../运维/Nginx限流.html">
            
                    
                    限流Nginx
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.4" data-path="../Java-Spring/负载均衡.html">
            
                <a href="../Java-Spring/负载均衡.html">
            
                    
                    负载均衡
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.5" data-path="../运维/Nginx负载均衡.html">
            
                <a href="../运维/Nginx负载均衡.html">
            
                    
                    负载均衡Nginx
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.6" data-path="../Java-其他库/熔断Hystrix.html">
            
                <a href="../Java-其他库/熔断Hystrix.html">
            
                    
                    熔断Hystrix
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.7" data-path="../Java-其他库/缓存.html">
            
                <a href="../Java-其他库/缓存.html">
            
                    
                    缓存
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.8" data-path="../Java-其他库/缓存.html">
            
                <a href="../Java-其他库/缓存.html#本地缓存">
            
                    
                    本地缓存
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.9" data-path="../Redis/Redis.html">
            
                <a href="../Redis/Redis.html">
            
                    
                    分布式缓存Redis
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.10" data-path="../Java-其他库/分布式事务.html">
            
                <a href="../Java-其他库/分布式事务.html">
            
                    
                    分布式事务
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.11" data-path="../Java-其他库/分布式事务.html">
            
                <a href="../Java-其他库/分布式事务.html#事务消息">
            
                    
                    可靠事务消息
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.12" data-path="../Java-Spring/业务监控.html">
            
                <a href="../Java-Spring/业务监控.html">
            
                    
                    业务监控
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.13" data-path="../Java-其他库/分布式定时作业.html">
            
                <a href="../Java-其他库/分布式定时作业.html">
            
                    
                    分布式作业调度ElasticJob
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.14" data-path="../Java-ORM/ORM.html">
            
                <a href="../Java-ORM/ORM.html">
            
                    
                    ORM
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.15" data-path="../Java-其他库/分布式系统及CAP原理.html">
            
                <a href="../Java-其他库/分布式系统及CAP原理.html">
            
                    
                    分布式系统及CAP原理
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.2.16" data-path="RabbitMQ笔记.html">
            
                <a href="RabbitMQ笔记.html">
            
                    
                    消息驱动Rabbitmq
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../category/数据库.html">
            
                <a href="../category/数据库.html">
            
                    
                    数据库
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="../Mysql/经典数据库设计案例.html">
            
                <a href="../Mysql/经典数据库设计案例.html">
            
                    
                    mysql设计
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="../Mysql/Mysql事务与锁.html">
            
                <a href="../Mysql/Mysql事务与锁.html">
            
                    
                    mysql事务与锁
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3" data-path="../Mysql/mysql数据类型.html">
            
                <a href="../Mysql/mysql数据类型.html">
            
                    
                    mysql数据类型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.4" data-path="../Mysql/mysql索引及查询.html">
            
                <a href="../Mysql/mysql索引及查询.html">
            
                    
                    mysql索引与查询
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.5" data-path="../Mysql/mysql索引及查询.html">
            
                <a href="../Mysql/mysql索引及查询.html#查询语句设计准则">
            
                    
                    mysql查询语句设计准则
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.6" data-path="../Mysql/mysql性能测试.html">
            
                <a href="../Mysql/mysql性能测试.html">
            
                    
                    mysql性能测试
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.7" data-path="../Mysql/mysql主从同步与读写分离.html">
            
                <a href="../Mysql/mysql主从同步与读写分离.html">
            
                    
                    mysql主从同步与读写分离
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.8" data-path="../Java-Spring/SpringBoot事务注解@Transactional.html">
            
                <a href="../Java-Spring/SpringBoot事务注解@Transactional.html">
            
                    
                    Spring事务注解@Transactional
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.9" data-path="../数据结构与算法/位运算应用实例.html">
            
                <a href="../数据结构与算法/位运算应用实例.html">
            
                    
                    位运算应用实例
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.10" data-path="../Mongodb-Client/morphia-API汇总.html">
            
                <a href="../Mongodb-Client/morphia-API汇总.html">
            
                    
                    morphia API汇总
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.11" data-path="../Mongodb-Client/mongo驱动连接.html">
            
                <a href="../Mongodb-Client/mongo驱动连接.html">
            
                    
                    mongodb驱动与连接
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.12" data-path="../Mongodb/mongodb-ObjectId实践.html">
            
                <a href="../Mongodb/mongodb-ObjectId实践.html">
            
                    
                    mongodb ObjectId实践
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.13" data-path="../Mongodb/mongodb角色权限.html">
            
                <a href="../Mongodb/mongodb角色权限.html">
            
                    
                    mongodb角色权限
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="../category/java并发.html">
            
                <a href="../category/java并发.html">
            
                    
                    Java并发
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="../Java-Base/Java并发.html">
            
                <a href="../Java-Base/Java并发.html">
            
                    
                    Java并发
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="../Java-Base/Java并发.html">
            
                <a href="../Java-Base/Java并发.html#锁">
            
                    
                    Java并发之锁设计
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.3" data-path="../Java-Base/Java并发.html">
            
                <a href="../Java-Base/Java并发.html#synchronized">
            
                    
                    Java并发之synchronized
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.4" data-path="../Java-Base/Java之Lock.html">
            
                <a href="../Java-Base/Java之Lock.html#reentrantlock">
            
                    
                    Java Lock之ReentrantLock
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.5" data-path="../Java-Base/Java之Lock.html">
            
                <a href="../Java-Base/Java之Lock.html#reentrantreadwritelock">
            
                    
                    Java Lock之ReentrantReadWriteLock
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.6" data-path="../Java-Base/Java之Future.html">
            
                <a href="../Java-Base/Java之Future.html">
            
                    
                    Java Future
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.7" data-path="../Java-Base/Java之Future.html">
            
                <a href="../Java-Base/Java之Future.html#futuretask">
            
                    
                    Java Future之FutureTask
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.8" data-path="../Java-Base/Java之Future.html">
            
                <a href="../Java-Base/Java之Future.html#completablefuture">
            
                    
                    Java Future之CompletableFuture
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.9" data-path="../Java-Base/Java之Future.html">
            
                <a href="../Java-Base/Java之Future.html#forkjointask">
            
                    
                    Java Future之ForkJoinTask
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.10" data-path="../Java-Base/Java之Thread.html">
            
                <a href="../Java-Base/Java之Thread.html">
            
                    
                    Java Thread
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="../category/redis.html">
            
                <a href="../category/redis.html">
            
                    
                    Redis
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="../Redis/Redis.html">
            
                <a href="../Redis/Redis.html">
            
                    
                    Redis
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2" data-path="../Redis/Redis.html">
            
                <a href="../Redis/Redis.html#集群">
            
                    
                    Redis集群
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.3" data-path="../Redis/Redis.html">
            
                <a href="../Redis/Redis.html#消息订阅">
            
                    
                    Redis消息订阅
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.4" data-path="../Redis/Redis.html">
            
                <a href="../Redis/Redis.html#lua">
            
                    
                    Redis Lua脚本
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.5" data-path="../Redis/Redis.html">
            
                <a href="../Redis/Redis.html#配置汇总">
            
                    
                    Redis配置汇总
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="../category/运维.html">
            
                <a href="../category/运维.html">
            
                    
                    运维
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.1" data-path="../运维/Linux常用操作汇总.html">
            
                <a href="../运维/Linux常用操作汇总.html">
            
                    
                    Linux常用操作汇总
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.2" data-path="../运维/阿里云笔记.html">
            
                <a href="../运维/阿里云笔记.html">
            
                    
                    阿里云笔记
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="../category/nginx.html">
            
                <a href="../category/nginx.html">
            
                    
                    Nginx
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.7.1" data-path="../运维/Nginx学习笔记.html">
            
                <a href="../运维/Nginx学习笔记.html">
            
                    
                    Nginx基础
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.2" data-path="../运维/Nginx负载均衡.html">
            
                <a href="../运维/Nginx负载均衡.html">
            
                    
                    Nginx负载均衡
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.3" data-path="../运维/Nginx限流.html">
            
                <a href="../运维/Nginx限流.html">
            
                    
                    Nginx限流
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.4" data-path="../运维/Nginx学习笔记.html">
            
                <a href="../运维/Nginx学习笔记.html#六、其他">
            
                    
                    Nginx客户端辅助技巧
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="../category/容器化.html">
            
                <a href="../category/容器化.html">
            
                    
                    容器化
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.8.1" data-path="../Docker/docker笔记.html">
            
                <a href="../Docker/docker笔记.html">
            
                    
                    Docker学习笔记
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.2" data-path="../Docker/docker笔记.html">
            
                <a href="../Docker/docker笔记.html#基础操作">
            
                    
                    Docker基础操作
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.3" data-path="../Docker/docker笔记.html">
            
                <a href="../Docker/docker笔记.html#dockerfile">
            
                    
                    DockerFile
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.9" data-path="../category/Web.html">
            
                <a href="../category/Web.html">
            
                    
                    Web
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.9.1" data-path="../运维/Http入坑Https笔记.html">
            
                <a href="../运维/Http入坑Https笔记.html">
            
                    
                    Http入坑Https笔记
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.2" data-path="../Web/阿里云OSS.html">
            
                <a href="../Web/阿里云OSS.html">
            
                    
                    OSS
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.10" data-path="../category/java基础.html">
            
                <a href="../category/java基础.html">
            
                    
                    Java基础
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.10.1" data-path="../Java-Base/Java基础.html">
            
                <a href="../Java-Base/Java基础.html#jvm">
            
                    
                    JVM基础
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.2" data-path="../Java-Base/Java基础.html">
            
                <a href="../Java-Base/Java基础.html#语法糖">
            
                    
                    Java语法糖
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.3" data-path="../Java-Base/Java基础.html">
            
                <a href="../Java-Base/Java基础.html#数据结构">
            
                    
                    Java数据结构
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.4" data-path="../Java-Base/Java8函数式编程.html">
            
                <a href="../Java-Base/Java8函数式编程.html">
            
                    
                    java8函数式编程
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.5" data-path="../Java-Base/ArrayList源码分析.html">
            
                <a href="../Java-Base/ArrayList源码分析.html">
            
                    
                    JDK源码分析ArrayList
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.6" data-path="../Java-Base/HashMap源码分析.html">
            
                <a href="../Java-Base/HashMap源码分析.html">
            
                    
                    JDK源码分析HashMap
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.7" data-path="../Java-Base/Java注解.html">
            
                <a href="../Java-Base/Java注解.html">
            
                    
                    Java注解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.8" data-path="../Java-Base/Timsort排序算法.html">
            
                <a href="../Java-Base/Timsort排序算法.html">
            
                    
                    Timsort排序算法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.9" data-path="../Java-Base/插入排序分析与Java实现.html">
            
                <a href="../Java-Base/插入排序分析与Java实现.html">
            
                    
                    插入排序分析与Java实现
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.11" data-path="../category/工具与规范.html">
            
                <a href="../category/工具与规范.html">
            
                    
                    工具与规范
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.11.1" data-path="../工具/Maven使用技巧汇总.html">
            
                <a href="../工具/Maven使用技巧汇总.html">
            
                    
                    Maven使用技巧
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.2" data-path="../编码规范/Java编码规范.html">
            
                <a href="../编码规范/Java编码规范.html">
            
                    
                    Java编码规范
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.12" data-path="../category/OLAP.html">
            
                <a href="../category/OLAP.html">
            
                    
                    OLAP
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.12.1" data-path="../数据处理/storm学习笔记.html">
            
                <a href="../数据处理/storm学习笔记.html">
            
                    
                    流式计算Storm学习笔记
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.13" data-path="../category/数据运营.html">
            
                <a href="../category/数据运营.html">
            
                    
                    数据运营
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.13.1" data-path="../数据运营/增长黑客数据运营.html">
            
                <a href="../数据运营/增长黑客数据运营.html">
            
                    
                    增长黑客-数据运营
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.14" data-path="../category/前端技术栈.html">
            
                <a href="../category/前端技术栈.html">
            
                    
                    前端技术栈
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.14.1" data-path="../前端/JavaScript设计模式.html">
            
                <a href="../前端/JavaScript设计模式.html">
            
                    
                    JavaScript设计模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.14.2" data-path="../前端/html相对路径与绝对路径.html">
            
                <a href="../前端/html相对路径与绝对路径.html">
            
                    
                    Html相对路径与绝对路径
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.14.3" data-path="../前端/微信小程序学习笔记.html">
            
                <a href="../前端/微信小程序学习笔记.html">
            
                    
                    微信小程序学习笔记
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.15" data-path="../category/个人.html">
            
                <a href="../category/个人.html">
            
                    
                    个人
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.15.1" data-path="../个人/简历.html">
            
                <a href="../个人/简历.html">
            
                    
                    简历
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >消息驱动Rabbitmq</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="rabbitmq&#x7B14;&#x8BB0;">RabbitMQ&#x7B14;&#x8BB0;</h1>
<h1 id="&#x57FA;&#x672C;&#x6982;&#x5FF5;">&#x57FA;&#x672C;&#x6982;&#x5FF5;</h1>
<h2 id="channel&#x3001;exchange&#x3001;queue">Channel&#x3001;Exchange&#x3001;Queue</h2>
<p>Channel&#xFF08;&#x4FE1;&#x9053;&#xFF09;&#xFF1A;</p>
<ul>
<li>&#x4E00;&#x4E2A;channel&#x53EA;&#x6709;&#x4E00;&#x4E2A;&#x7EBF;&#x7A0B;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;</li>
<li>&#x6D88;&#x606F;&#x5728;channel&#x4E0A;&#x6295;&#x653E;&#x662F;&#x6709;&#x987A;&#x5E8F;&#x7684;</li>
</ul>
<p>Exchange&#xFF08;&#x4EA4;&#x6362;&#x673A;&#xFF09;&#xFF1A;&#x7528;&#x4E8E;&#x8F6C;&#x53D1;&#x6D88;&#x606F;</p>
<ul>
<li><strong>&#x4E0D;&#x505A;&#x5B58;&#x50A8;</strong>&#xFF1A;&#x5982;&#x679C;&#x6CA1;&#x6709;&#x961F;&#x5217;&#x63A5;&#x6536;&#x76F4;&#x63A5;&#x4E22;&#x5F03;</li>
</ul>
<p>Queue</p>
<ul>
<li>&#x961F;&#x5217;&#x7684;&#x6301;&#x4E45;&#x5316;&#x53EA;&#x4FDD;&#x8BC1;&#x961F;&#x5217;&#x7684;&#x5143;&#x6570;&#x636E;&#x4E0D;&#x4F1A;&#x4E22;&#x5931;&#xFF0C;&#x4E0D;&#x4FDD;&#x8BC1;&#x6D88;&#x606F;&#x4E0D;&#x4E22;&#x5931;&#xFF0C;&#x8BBE;&#x7F6E;durable&#x53C2;&#x6570;</li>
<li>&#x6D88;&#x606F;&#x672C;&#x8EAB;&#x7684;&#x6301;&#x4E45;&#x5316;&#xFF0C;&#x6295;&#x9012;&#x6D88;&#x606F;&#x65F6;&#x8BBE;&#x7F6E;<code>AMQP.BasicProperties</code>&#x7684;&#x5C5E;&#x6027;<code>deliveryMode</code>&#x4E3A;2</li>
</ul>
<pre><code class="lang-java">AMQP.BasicProperties low = <span class="hljs-keyword">new</span> AMQP.BasicProperties
   .Builder()
   .deliveryMode(<span class="hljs-number">2</span>)
   .build();
</code></pre>
<h2 id="&#x6D88;&#x606F;&#x5206;&#x53D1;">&#x6D88;&#x606F;&#x5206;&#x53D1;</h2>
<p>&#x6D88;&#x606F;&#x5C06;&#x4EE5;&#x5FAA;&#x73AF;&#xFF08;round-robin&#xFF09;&#x7684;&#x65B9;&#x5F0F;&#x53D1;&#x9001;&#x7ED9;&#x6D88;&#x8D39;&#x8005;&#x3002;&#x6BCF;&#x6761;&#x6D88;&#x606F;&#x53EA;&#x4F1A;&#x5206;&#x53D1;&#x7ED9;&#x4E00;&#x4E2A;&#x8BA2;&#x9605;&#x7684;&#x6D88;&#x8D39;&#x8005;</p>
<h2 id="&#x4EA4;&#x6362;&#x5668;exchange-3&#x79CD;&#x7C7B;&#x578B;">&#x4EA4;&#x6362;&#x5668;Exchange 3&#x79CD;&#x7C7B;&#x578B;</h2>
<ol>
<li>direct&#xFF1A;&#x8DEF;&#x7531;key&#x5B8C;&#x5168;&#x5339;&#x914D;&#xFF0C;&#x6295;&#x9012;&#x5230;&#x54CD;&#x5E94;&#x961F;&#x5217;</li>
<li>fanout&#xFF1A;1&#x5BF9;&#x591A;&#xFF0C;1&#x4E2A;&#x4EA4;&#x6362;&#x5668;&#x6536;&#x5230;&#x6D88;&#x606F;&#xFF0C;&#x5E7F;&#x64AD;&#x5230;&#x6240;&#x6709;&#x7ED1;&#x5B9A;&#x961F;&#x5217;</li>
<li>topic&#xFF1A;&#x591A;&#x5BF9;1&#xFF0C;&#x4E0D;&#x540C;&#x6D88;&#x606F;&#x6765;&#x6E90;&#xFF0C;&#x540C;&#x65F6;&#x6C47;&#x603B;&#x5230;&#x4E00;&#x4E2A;&#x961F;&#x5217;&#xFF0C;&#x53EF;&#x4EE5;&#x7528;&#x901A;&#x914D;&#x7B26;</li>
</ol>
<h1 id="&#x6301;&#x4E45;&#x5316;&#x7B56;&#x7565;">&#x6301;&#x4E45;&#x5316;&#x7B56;&#x7565;</h1>
<ul>
<li>Exchange&#x6301;&#x4E45;&#x5316;&#xFF1A;&#x4EC5;&#x6301;&#x4E45;&#x5316;&#x5143;&#x6570;&#x636E;&#xFF0C;&#x670D;&#x52A1;&#x5B95;&#x673A;&#x540E;&#xFF0C;Exchange&#x9700;&#x8981;&#x91CD;&#x5EFA;</li>
<li>Queue&#x6301;&#x4E45;&#x5316;&#xFF1A;&#x6301;&#x4E45;&#x5316;&#x961F;&#x5217;&#x5143;&#x6570;&#x636E;&#x53CA;&#x6D88;&#x606F;&#xFF0C;&#x5B95;&#x673A;&#x540E;&#xFF0C;&#x6D88;&#x606F;&#x4E0D;&#x4E22;&#x5931;</li>
</ul>
<p>Exchange&#x58F0;&#x660E;&#x6301;&#x4E45;&#x5316;</p>
<pre><code class="lang-java"><span class="hljs-comment">//type: direct&#x3001;fanout&#x3001;topic</span>
<span class="hljs-function"><span class="hljs-keyword">public</span> DeclareOk <span class="hljs-title">exchangeDeclare</span><span class="hljs-params">(String exchange, String type, <span class="hljs-keyword">boolean</span> durable)</span> <span class="hljs-keyword">throws</span> IOException </span>{
    <span class="hljs-keyword">return</span> <span class="hljs-keyword">this</span>.exchangeDeclare(exchange, (String)type, durable, <span class="hljs-keyword">false</span>, (Map)<span class="hljs-keyword">null</span>);
}
</code></pre>
<p>Queue&#x58F0;&#x660E;&#x6301;&#x4E45;&#x5316;</p>
<pre><code class="lang-java"><span class="hljs-keyword">public</span> com.rabbitmq.client.impl.AMQImpl.Queue.<span class="hljs-function">DeclareOk <span class="hljs-title">queueDeclare</span><span class="hljs-params">(String queue, <span class="hljs-keyword">boolean</span> durable, <span class="hljs-keyword">boolean</span> exclusive, <span class="hljs-keyword">boolean</span> autoDelete, Map&lt;String, Object&gt; arguments)</span> <span class="hljs-keyword">throws</span> IOException </span>{
    validateQueueNameLength(queue);
    <span class="hljs-keyword">return</span> (com.rabbitmq.client.impl.AMQImpl.Queue.DeclareOk)<span class="hljs-keyword">this</span>.exnWrappingRpc((<span class="hljs-keyword">new</span> com.rabbitmq.client.AMQP.Queue.Declare.Builder()).queue(queue).durable(durable).exclusive(exclusive).autoDelete(autoDelete).arguments(arguments).build()).getMethod();
}
</code></pre>
<p>Message&#x58F0;&#x660E;&#x6301;&#x4E45;&#x5316;&#xFF0C;&#x6295;&#x9012;&#x6A21;&#x5F0F;&#x8BBE;&#x4E3A;2&#xFF0C;&#x8868;&#x793A;&#x6301;&#x4E45;&#x5316;</p>
<pre><code class="lang-java">String message = <span class="hljs-string">&quot;durable exchange test&quot;</span>;
<span class="hljs-comment">//&#x6295;&#x9012;&#x6A21;&#x5F0F;&#x8BBE;&#x4E3A;2</span>
AMQP.BasicProperties props = <span class="hljs-keyword">new</span> MQP.BasicProperties().builder().deliveryMode(<span class="hljs-number">2</span>).build();
channel.basicPublish(EXCHANGE_NAME, <span class="hljs-string">&quot;&quot;</span>, props, message.getBytes());
</code></pre>
<h2 id="rabbitmq&#x6CA1;&#x6709;&#x673A;&#x5236;&#x4FDD;&#x8BC1;&#x767E;&#x5206;&#x767E;&#x4E0D;&#x4E22;&#x5931;">rabbitmq&#x6CA1;&#x6709;&#x673A;&#x5236;&#x4FDD;&#x8BC1;&#x767E;&#x5206;&#x767E;&#x4E0D;&#x4E22;&#x5931;</h2>
<p>&#x6CE8;&#x610F;&#xFF1A;&#x5373;&#x4F7F;&#x5F00;&#x542F;&#x6301;&#x4E45;&#x5316;&#xFF0C;rabbitmq&#x6CA1;&#x6709;&#x673A;&#x5236;&#x4FDD;&#x8BC1;&#x767E;&#x5206;&#x767E;&#x4E0D;&#x4E22;&#x5931;</p>
<p>mq&#x8282;&#x70B9;&#x5B95;&#x673A;&#xFF0C;&#x6709;&#x6D88;&#x606F;&#x8FD8;&#x6CA1;&#x5B8C;&#x6210;&#x5199;&#x5165;&#x78C1;&#x76D8;&#xFF0C;&#x5C31;&#x4F1A;&#x4E22;&#x5931;</p>
<h1 id="&#x786E;&#x8BA4;&#x7B56;&#x7565;">&#x786E;&#x8BA4;&#x7B56;&#x7565;</h1>
<ul>
<li>Confirm&#xFF1A;&#x76F4;&#x63A5;&#x4F20;&#x9001;&#x6D88;&#x606F; client &gt; mq, &#x63A5;&#x6536;&#x5230; mq &gt; ack, mq &#x5728;&#x5F02;&#x6B65;&#x7684;&#x5B8C;&#x6210; &#x63A5;&#x4E0B;&#x6765;&#x7684;&#x4E8B;&#x60C5;</li>
<li>Transaction&#xFF1A;client &#x8BF7;&#x6C42;&#x5F00;&#x542F;&#x4E8B;&#x52A1;  &gt; &#x53D1;&#x9001;message &gt; client &#x63D0;&#x4EA4;&#x4E8B;&#x52A1;&#xFF0C;&#x6574;&#x4E2A;&#x8FC7;&#x7A0B;&#x662F;&#x540C;&#x6B65;&#x7684;&#xFF0C;<strong>mq&#x5FC5;&#x987B;&#x5B8C;&#x6210;&#x6D88;&#x606F;&#x6301;&#x4E45;&#x5316;&#x3001;&#x6D88;&#x606F;&#x540C;&#x6B65;&#x7B49;</strong>&#x3002;</li>
</ul>
<table>
<thead>
<tr>
<th>&#x6A21;&#x5F0F;</th>
<th>&#x5F02;&#x6B65;&#x53D1;&#x5230;mq</th>
<th>&#x4F18;&#x70B9;</th>
<th>&#x7F3A;&#x70B9;</th>
<th>&#x9ED8;&#x8BA4;&#x6A21;&#x5F0F;</th>
</tr>
</thead>
<tbody>
<tr>
<td>Confrim</td>
<td>&#x5F02;&#x6B65;</td>
<td>&#x6027;&#x80FD;&#x597D;</td>
<td>&#x53EF;&#x80FD;&#x51FA;&#x73B0;&#x53D1;&#x9001;&#x4E86;10&#x6761;&#x6D88;&#x606F;&#xFF0C;mq&#x5B95;&#x673A;&#x53EA;&#x6536;&#x5230;6&#x6761;&#xFF0C;&#x4F46;&#x5269;&#x4F59;4&#x6761;&#x53D1;&#x9001;&#x5931;&#x8D25;client&#x4E0D;&#x77E5;&#x9053;</td>
<td>&#x662F;</td>
</tr>
<tr>
<td>Transaction</td>
<td>&#x540C;&#x6B65;</td>
<td>&#x540C;&#x6B65;&#x53D1;&#x9001;&#xFF0C;&#x8981;&#x7B49;MQ&#x786E;&#x8BA4;&#xFF0C;&#x6548;&#x7387;&#x4F4E;</td>
<td>&#x4FDD;&#x8BC1;&#x53EF;&#x9760;&#x6027;</td>
<td>&#x5426;</td>
</tr>
</tbody>
</table>
<p>Confirm&#x6A21;&#x5F0F;&#x63D0;&#x4F9B;&#x901A;&#x77E5;&#x5DF2;&#x63A5;&#x6536;&#x6D88;&#x606F;&#x673A;&#x5236;</p>
<h1 id="&#x96C6;&#x7FA4;">&#x96C6;&#x7FA4;</h1>
<h2 id="&#x9AD8;&#x53EF;&#x7528;ha">&#x9AD8;&#x53EF;&#x7528;HA</h2>
<p>rabbitMQ&#x4E24;&#x79CD;HA&#x6A21;&#x5F0F;</p>
<h3 id="&#x666E;&#x901A;ha&#x6A21;&#x5F0F;">&#x666E;&#x901A;HA&#x6A21;&#x5F0F;</h3>
<p><img src="assets/rabbitmq&#x9AD8;&#x53EF;&#x7528;&#x666E;&#x901A;&#x6A21;&#x5F0F;&#x5DE5;&#x4F5C;&#x539F;&#x7406;.png" alt="rabbitmq&#x9AD8;&#x53EF;&#x7528;&#x666E;&#x901A;&#x6A21;&#x5F0F;&#x5DE5;&#x4F5C;&#x539F;&#x7406;"></p>
<p>&#x5DE5;&#x4F5C;&#x539F;&#x7406;</p>
<ul>
<li>&#x6240;&#x6709;&#x8282;&#x70B9;&#x4FDD;&#x5B58;&#x6240;&#x6709;Exchange&#x3001;Queue&#x5143;&#x6570;&#x636E;</li>
<li>&#x7528;&#x6237;&#x8FDE;&#x63A5;&#x4EFB;&#x610F;&#x8282;&#x70B9;&#xFF0C;&#x5C31;&#x53EF;&#x4EE5;&#x76D1;&#x542C;&#x961F;&#x5217;&#x4E0A;&#x6D88;&#x606F;</li>
<li>&#x5F53;&#x6D88;&#x8D39;&#x8005;&#x8BF7;&#x6C42;&#x670D;&#x52A1;C&#x62C9;&#x6D88;&#x606F;&#xFF0C;C&#x6CA1;&#x6709;&#xFF0C;C&#x8BF7;&#x6C42;B&#x62C9;&#x6D88;&#x606F;&#xFF0C;&#x518D;&#x63D0;&#x4F9B;&#x7ED9;&#x6D88;&#x8D39;&#x8005;&#x6D88;&#x8D39;</li>
</ul>
<p>&#x7F3A;&#x70B9;&#x662F;&#x663E;&#x800C;&#x6613;&#x89C1;&#x7684;</p>
<ul>
<li>&#x5F53;B&#x4E5F;&#x6CA1;&#x6709;&#x6D88;&#x606F;&#x7684;&#x65F6;&#x5019;&#xFF0C;B&#x4F1A;&#x518D;&#x53D6;&#x8BF7;&#x6C42;A&#x3002;&#x5BFC;&#x81F4;MQ&#x96C6;&#x7FA4;&#x5185;&#x9891;&#x7E41;&#x7684;&#x6570;&#x636E;&#x4EA4;&#x4E92;&#xFF0C;&#x8017;&#x8D39;&#x8D44;&#x6E90;</li>
<li>&#x5F53;&#x4EFB;&#x610F;&#x8282;&#x70B9;&#x5B95;&#x673A;&#xFF0C;&#x6D88;&#x606F;&#x53EF;&#x80FD;&#x4E22;&#x5931;&#xFF0C;&#x6CA1;&#x6709;HA&#x6548;&#x679C;</li>
</ul>
<h3 id="&#x955C;&#x50CF;ha&#x6A21;&#x5F0F;">&#x955C;&#x50CF;HA&#x6A21;&#x5F0F;</h3>
<p><img src="assets/rabbitmq&#x9AD8;&#x53EF;&#x7528;&#x955C;&#x50CF;&#x6A21;&#x5F0F;&#x5DE5;&#x4F5C;&#x539F;&#x7406;.png" alt="rabbitmq&#x9AD8;&#x53EF;&#x7528;&#x955C;&#x50CF;&#x6A21;&#x5F0F;&#x5DE5;&#x4F5C;&#x539F;&#x7406;"></p>
<p>&#x5DE5;&#x4F5C;&#x539F;&#x7406;</p>
<ul>
<li>&#x4E3B;&#x52A8;&#x590D;&#x5236;&#x6D88;&#x606F;&#x5230;&#x955C;&#x50CF;&#x8282;&#x70B9;</li>
<li>&#x6D88;&#x8D39;&#x7AEF;&#x8FDE;&#x63A5;&#x4EFB;&#x610F;&#x8282;&#x70B9;&#x90FD;&#x80FD;&#x62C9;&#x53D6;&#x6D88;&#x606F;</li>
</ul>
<p>&#x7F3A;&#x70B9;&#x663E;&#x800C;&#x6613;&#x89C1;</p>
<ul>
<li>&#x8282;&#x70B9;&#x6570;&#x91CF;&#x8F83;&#x591A;&#x65F6;&#xFF0C;&#x540C;&#x6B65;&#x6D88;&#x606F;&#x8017;&#x8D39;&#x7684;&#x8D44;&#x6E90;&#x60CA;&#x4EBA;</li>
</ul>
<p>&#x4E24;&#x79CD;&#x6A21;&#x5F0F;&#x7684;&#x53D6;&#x820D;&#xFF1A;&#x53EF;&#x9760;&#x6027;&#x8981;&#x6C42;&#x9AD8;&#xFF0C;&#x4F7F;&#x7528;&#x955C;&#x50CF;&#x6A21;&#x5F0F;</p>
<h2 id="&#x8D1F;&#x8F7D;&#x5747;&#x8861;">&#x8D1F;&#x8F7D;&#x5747;&#x8861;</h2>
<p>&#x65B9;&#x6848;&#xFF1A;keepalived + HAproxy</p>
<ul>
<li>keepalived &#xFF1A;&#x63D0;&#x4F9B;&#x865A;&#x62DF;IP&#x534F;&#x8BAE;&#x3001;&#x8D1F;&#x8D23;HAproxy&#x7684;&#x9AD8;&#x53EF;&#x7528;</li>
<li>HAproxy&#xFF1A;&#x8D1F;&#x8D23;&#x8D1F;&#x8F7D;&#x4E0A;&#x6E38;&#x6295;&#x653E;&#x6D88;&#x606F;&#x8BF7;&#x6C42;</li>
</ul>
<p>&#x5DE5;&#x4F5C;&#x539F;&#x7406;</p>
<p><img src="assets/1585708355589.png" alt="1585708355589"></p>
<ul>
<li>HAproxy&#x662F;&#x5355;&#x70B9;</li>
<li>HAproxy&#x96C6;&#x7FA4;&#x5185;&#x8282;&#x70B9;&#x5B95;&#x673A;&#xFF0C;Keepalived&#x5524;&#x9192;&#x5E76;&#x5207;&#x6362;&#x4E3B;&#x8282;&#x70B9;</li>
</ul>
<p>HAproxy&#x914D;&#x7F6E;&#x53C2;&#x8003;&#xFF1A;<a href="../&#x5FAE;&#x670D;&#x52A1;/HAproxy&#x8D1F;&#x8F7D;&#x5747;&#x8861;&#x5668;.md">HAproxy&#x8D1F;&#x8F7D;&#x5747;&#x8861;&#x5668;</a></p>
<h1 id="&#x5BA2;&#x6237;&#x7AEF;">&#x5BA2;&#x6237;&#x7AEF;</h1>
<h2 id="socket&#x957F;&#x8FDE;&#x63A5;or&#x957F;&#x8F6E;&#x8BE2;">Socket&#x957F;&#x8FDE;&#x63A5;or&#x957F;&#x8F6E;&#x8BE2;</h2>
<p>&#x53C2;&#x8003;&#x6E90;&#x7801;&#x53EF;&#x77E5;&#xFF0C;RabbitMQ Client&#x662F;&#x901A;&#x8FC7;javax.net.SocketFactory&#x5EFA;&#x7ACB;tcp&#x957F;&#x8FDE;&#x63A5;&#xFF0C;&#x5B9E;&#x73B0;consumer client&#x7AEF;&#x4E0E;mq server&#x7AEF;&#x901A;&#x8BAF;&#x3002;&#x901A;&#x8FC7;&#x8BA2;&#x9605;&#x65B9;&#x6CD5;&#x88AB;&#x52A8;&#x4ECE;Queue&#x4E2D;&#x62C9;&#x53D6;&#x6D88;&#x606F;&#xFF0C;&#x4F2A;&#x4EE3;&#x7801;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre><code class="lang-java">ConnectionFactory factory = <span class="hljs-keyword">new</span> ConnectionFactory();
Connection conn = factory.newConnection();
Channel channel=conn.createChannel();
</code></pre>
<blockquote>
<p>&#x6CE8;&#x610F;&#xFF1A;
&#x521B;&#x5EFA;Connection&#x9700;&#x8981;&#x6307;&#x5B9A;MQ&#x7684;&#x7269;&#x7406;&#x5730;&#x5740;&#x548C;&#x7AEF;&#x53E3;&#xFF0C;&#x662F;socket &gt; &gt; tcp&#x7269;&#x7406;&#x8FDE;&#x63A5;&#xFF0C;&#x800C;channel&#x662F;&#x4E00;&#x4E2A;&#x903B;&#x8F91;&#x7684;&#x6982;&#x5FF5;&#xFF0C;&#x652F;&#x6301;&#x5728;tcp&#x8FDE;&#x63A5;&#x4E0A;&#x521B;&#x5EFA;&#x591A;&#x4E2A;MQ &#x3002;</p>
</blockquote>
<hr>
<h2 id="&#x5173;&#x952E;&#x6B65;&#x9AA4;&#x6E90;&#x7801;&#x5206;&#x6790;">&#x5173;&#x952E;&#x6B65;&#x9AA4;&#x6E90;&#x7801;&#x5206;&#x6790;</h2>
<h3 id="&#x521B;&#x5EFA;tcp&#x8FDE;&#x63A5;">&#x521B;&#x5EFA;TCP&#x8FDE;&#x63A5;</h3>
<p>&#x521B;&#x5EFA;Socket&#x6838;&#x5FC3;&#x6E90;&#x7801;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre><code class="lang-java"><span class="hljs-keyword">import</span> javax.net.SocketFactory;

<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">SocketFrameHandlerFactory</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">AbstractFrameHandlerFactory</span> </span>{
    <span class="hljs-keyword">private</span> <span class="hljs-keyword">final</span> SocketFactory factory;
    ...
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">SocketFrameHandlerFactory</span><span class="hljs-params">(<span class="hljs-keyword">int</span> connectionTimeout, SocketFactory factory, SocketConfigurator configurator, <span class="hljs-keyword">boolean</span> ssl, ExecutorService shutdownExecutor)</span> </span>{
        <span class="hljs-keyword">super</span>(connectionTimeout, configurator, ssl);
        <span class="hljs-keyword">this</span>.factory = factory;
        <span class="hljs-keyword">this</span>.shutdownExecutor = shutdownExecutor;
    }

    <span class="hljs-function"><span class="hljs-keyword">public</span> FrameHandler <span class="hljs-title">create</span><span class="hljs-params">(Address addr)</span> <span class="hljs-keyword">throws</span> IOException </span>{
        String hostName = addr.getHost();
        <span class="hljs-keyword">int</span> portNumber = ConnectionFactory.portOrDefault(addr.getPort(), <span class="hljs-keyword">this</span>.ssl);
        Socket socket = <span class="hljs-keyword">null</span>;

        <span class="hljs-keyword">try</span> {
            <span class="hljs-comment">//&#x901A;&#x8FC7;javax.net.SocketFactory&#x5EFA;&#x7ACB;tcp&#x957F;&#x8FDE;&#x63A5;</span>
            socket = <span class="hljs-keyword">this</span>.factory.createSocket();
            <span class="hljs-keyword">this</span>.configurator.configure(socket);
            socket.connect(<span class="hljs-keyword">new</span> InetSocketAddress(hostName, portNumber), <span class="hljs-keyword">this</span>.connectionTimeout);
            <span class="hljs-keyword">return</span> <span class="hljs-keyword">this</span>.create(socket);
        } <span class="hljs-keyword">catch</span> (IOException var6) {
            quietTrySocketClose(socket);
            <span class="hljs-keyword">throw</span> var6;
        }
    }
    ...
}
</code></pre>
<hr>
<h3 id="&#x8BFB;&#x53D6;&#x6D88;&#x606F;">&#x8BFB;&#x53D6;&#x6D88;&#x606F;</h3>
<p>&#x521B;&#x5EFA;Connection&#x8FDE;&#x63A5;&#x540E;&#xFF0C;&#x901A;&#x8FC7;&#x542F;&#x52A8;MainLoop&#x540E;&#x53F0;&#x7EBF;&#x7A0B;&#xFF0C;&#x65E0;&#x95F4;&#x65AD;&#x4ECE;socket&#xFF08;FrameHandler&#xFF09;&#x4E2D;&#x83B7;&#x53D6;&#x6570;&#x636E;&#x5305;Frame&#x3002;&#x6CE8;&#x610F;readFrame()&#x53EF;&#x80FD;&#x629B;&#x51FA;SocketTimeoutException&#x8D85;&#x65F6;&#x5F02;&#x5E38;&#x3002;&#x4F46;&#x6CE8;&#x610F;&#xFF0C;socket&#x8BFB;&#x53D6;&#x8D85;&#x65F6;&#x5E76;&#x975E;mq&#x5B9E;&#x4F8B;&#x7684;&#x8FDE;&#x63A5;&#x8D85;&#x65F6;&#xFF0C;&#x662F;&#x4ECE;socket&#x4E2D;&#x8BFB;&#x53D6;&#x5B57;&#x8282;&#x6D41;&#x7684;&#x7B49;&#x5F85;&#x65F6;&#x95F4;&#x3002;&#x8FD9;&#x4E2A;&#x8D85;&#x65F6;&#x65F6;&#x95F4;&#x9ED8;&#x8BA4;&#x4E3A;10&#x79D2;&#xFF0C;&#x7531;<code>AMQConnection.HANDSHAKE_TIMEOUT</code>&#x5E38;&#x91CF;&#x6307;&#x5B9A;&#x3002;&#x6E90;&#x7801;&#x7B80;&#x5316;&#x540E;&#x903B;&#x8F91;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre><code>private class MainLoop implements Runnable {
    private MainLoop() {
    }

    public void run() {
        //while(true)&#x5B9E;&#x73B0;&#x65E0;&#x9650;&#x5FAA;&#x73AF;
        while(true) {
            try {
                //&#x9000;&#x51FA;&#x6761;&#x4EF6;&#x662F;&#xFF1A;AMQConnection&#x72B6;&#x6001;&#x975E;&#x8FD0;&#x884C;&#x65F6;&#xFF0C;&#x83B7;&#x53D6;&#x6355;&#x6349;&#x5F02;&#x5E38;
                if(AMQConnection.this._running) {
                    Frame ex = AMQConnection.this._frameHandler.readFrame();
                    AMQConnection.this.readFrame(ex);
                    continue;
                }
            } catch (Throwable var5) {
                ...
            }
            return;
        }
    }
}

class SocketFrameHandler implements FrameHandler{
    public Frame readFrame() throws IOException {
        //&#x901A;&#x8FC7;DataInputStream&#x5B9E;&#x73B0;&#x6570;&#x636E;&#x83B7;&#x53D6;
        DataInputStream var1 = this._inputStream;
        synchronized(this._inputStream) {
            int type;
            try {
                // &#x4ECE;&#x201C;&#x6570;&#x636E;&#x8F93;&#x5165;&#x6D41;&#x201D;&#x4E2D;&#x8BFB;&#x53D6;&#x201C;&#x65E0;&#x7B26;&#x53F7;&#x7684;Byte&#x7C7B;&#x578B;&#x201D;&#x7684;&#x503C;&#xFF0C;&#x5373;&#x8BFB;&#x53D6;&#x503C;&#x4E3A;&#x6B63;&#x6570;&#x7684;byte&#x503C;
                type = is.readUnsignedByte();
            } catch (SocketTimeoutException&#xFF0C; var6) {
                //&#x6CE8;&#x610F;&#xFF1A;readFrame()&#x6B64;&#x5904;&#x4F1A;&#x629B;&#x51FA;SocketTimeoutException&#xFF0C;socket&#x8BFB;&#x53D6;&#x8D85;&#x65F6;&#x5E76;&#x975E;mq&#x5B9E;&#x4F8B;&#x7684;&#x8FDE;&#x63A5;&#x8D85;&#x65F6;&#xFF0C;&#x662F;&#x4ECE;socket&#x4E2D;&#x8BFB;&#x53D6;&#x5B57;&#x8282;&#x6D41;&#x7684;&#x7B49;&#x5F85;&#x65F6;&#x95F4;&#xFF0C;&#x9ED8;&#x8BA4;&#x4E3A;10&#x79D2;&#xFF0C;&#x7531;`AMQConnection.HANDSHAKE_TIMEOUT`&#x5E38;&#x91CF;&#x6307;&#x5B9A;
                return null;
            }

            if(type == 65) {
                protocolVersionMismatch(is);
            }

            //&#x8BFB;&#x53D6;&#x51FA;&#x8F93;&#x5165;&#x6D41;&#x4E2D;&#x7684;UTF-8&#x6570;&#x636E;&#x7684;&#x957F;&#x5EA6;
            int channel = is.readUnsignedShort();

            // &#x4ECE;&#x201C;&#x6570;&#x636E;&#x8F93;&#x5165;&#x6D41;&#x201D;&#x4E2D;&#x8BFB;&#x53D6;&#x201C;int&#x7C7B;&#x578B;&#x201D;&#x7684;&#x503C;
            int payloadSize = is.readInt();
            byte[] payload = new byte[payloadSize];

            // &#x4ECE;&#x201C;&#x6570;&#x636E;&#x8F93;&#x5165;&#x6D41;&#x201D;&#x4E2D;&#x8BFB;&#x53D6;&#x201C;long&#x7C7B;&#x578B;&#x201D;&#x7684;&#x503C;
            is.readFully(payload);
            int frameEndMarker = is.readUnsignedByte();
            if(frameEndMarker != 206) {
                throw new MalformedFrameException(&quot;Bad frame end marker: &quot; + frameEndMarker);
            } else {
                return new Frame(type, channel, payload);
            }
        }
    }
}
</code></pre><p>&#x66F4;&#x591A;&#x5173;&#x4E8E;<code>DataInputStream</code>&#x6280;&#x5DE7;&#x53C2;&#x8003;&#xFF1A;<a href="http://www.cnblogs.com/skywang12345/p/io_14.html" target="_blank">java io&#x7CFB;&#x5217;14&#x4E4B; DataInputStream(&#x6570;&#x636E;&#x8F93;&#x5165;&#x6D41;)&#x7684;&#x8BA4;&#x77E5;&#x3001;&#x6E90;&#x7801;&#x548C;&#x793A;&#x4F8B;</a></p>
<footer class="page-footer"><span class="copyright">Copyright &#xA9; tgor.top 2019 all right reserved&#xFF0C;powered by Gitbook</span><span class="footer-modification">&#x8BE5;&#x6587;&#x4EF6;&#x4FEE;&#x8BA2;&#x65F6;&#x95F4;&#xFF1A;
2020-04-23 15:32:53
</span></footer>
<script>console.log("plugin-popup....");document.onclick = function(e){ e.target.tagName === "IMG" && window.open(e.target.src,e.target.src)}</script><style>img{cursor:pointer}</style>
                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="../Java-其他库/分布式系统及CAP原理.html" class="navigation navigation-prev " aria-label="Previous page: 分布式系统及CAP原理">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="../category/数据库.html" class="navigation navigation-next " aria-label="Next page: 数据库">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"消息驱动Rabbitmq","level":"1.2.16","depth":2,"next":{"title":"数据库","level":"1.3","depth":1,"path":"category/数据库.md","ref":"category/数据库.md","articles":[{"title":"mysql设计","level":"1.3.1","depth":2,"path":"Mysql/经典数据库设计案例.md","ref":"Mysql/经典数据库设计案例.md","articles":[]},{"title":"mysql事务与锁","level":"1.3.2","depth":2,"path":"Mysql/Mysql事务与锁.md","ref":"Mysql/Mysql事务与锁.md","articles":[]},{"title":"mysql数据类型","level":"1.3.3","depth":2,"path":"Mysql/mysql数据类型.md","ref":"Mysql/mysql数据类型.md","articles":[]},{"title":"mysql索引与查询","level":"1.3.4","depth":2,"path":"Mysql/mysql索引及查询.md","ref":"Mysql/mysql索引及查询.md","articles":[]},{"title":"mysql查询语句设计准则","level":"1.3.5","depth":2,"anchor":"#查询语句设计准则","path":"Mysql/mysql索引及查询.md","ref":"Mysql/mysql索引及查询.md#查询语句设计准则","articles":[]},{"title":"mysql性能测试","level":"1.3.6","depth":2,"path":"Mysql/mysql性能测试.md","ref":"Mysql/mysql性能测试.md","articles":[]},{"title":"mysql主从同步与读写分离","level":"1.3.7","depth":2,"path":"Mysql/mysql主从同步与读写分离.md","ref":"Mysql/mysql主从同步与读写分离.md","articles":[]},{"title":"Spring事务注解@Transactional","level":"1.3.8","depth":2,"path":"Java-Spring/SpringBoot事务注解@Transactional.md","ref":"Java-Spring/SpringBoot事务注解@Transactional.md","articles":[]},{"title":"位运算应用实例","level":"1.3.9","depth":2,"path":"数据结构与算法/位运算应用实例.md","ref":"数据结构与算法/位运算应用实例.md","articles":[]},{"title":"morphia API汇总","level":"1.3.10","depth":2,"path":"Mongodb-Client/morphia-API汇总.md","ref":"Mongodb-Client/morphia-API汇总.md","articles":[]},{"title":"mongodb驱动与连接","level":"1.3.11","depth":2,"path":"Mongodb-Client/mongo驱动连接.md","ref":"Mongodb-Client/mongo驱动连接.md","articles":[]},{"title":"mongodb ObjectId实践","level":"1.3.12","depth":2,"path":"Mongodb/mongodb-ObjectId实践.md","ref":"Mongodb/mongodb-ObjectId实践.md","articles":[]},{"title":"mongodb角色权限","level":"1.3.13","depth":2,"path":"Mongodb/mongodb角色权限.md","ref":"Mongodb/mongodb角色权限.md","articles":[]}]},"previous":{"title":"分布式系统及CAP原理","level":"1.2.15","depth":2,"path":"Java-其他库/分布式系统及CAP原理.md","ref":"Java-其他库/分布式系统及CAP原理.md","articles":[]},"dir":"ltr"},"config":{"plugins":["chapter-fold","splitter","tbfed-pagefooter","page-toc-button","-search","search-pro","popup","back-to-top-button","code","copy-code-button"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"tbfed-pagefooter":{"copyright":"Copyright &copy tgor.top 2019","modify_label":"该文件修订时间：","modify_format":"YYYY-MM-DD HH:mm:ss"},"chapter-fold":{},"splitter":{},"search-pro":{"cutWordLib":"nodejieba","defineWord":["Gitbook Use"]},"popup":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"code":{"copyButtons":true},"fontsettings":{"theme":"sepia","family":"serif","size":1},"highlight":{},"page-toc-button":{"maxTocDepth":2,"minTocSize":2},"back-to-top-button":{},"copy-code-button":{},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","author":"tgor","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"tgor note","gitbook":"*","description":"tgor生活工作记录"},"file":{"path":"MQ/RabbitMQ笔记.md","mtime":"2020-04-23T07:32:53.353Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2020-04-29T08:43:24.127Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-chapter-fold/chapter-fold.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-splitter/splitter.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-page-toc-button/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search-pro/jquery.mark.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search-pro/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-back-to-top-button/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-code/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-copy-code-button/toggle.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

